package com.dxf.bigdata.D05_spark_again.action

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

/**
 *  初始值,分区内规则,分区间规则
 */
object aggregate {

  def main(args: Array[String]): Unit = {

    val sparkConf = new SparkConf().setMaster("local[*]").setAppName("app")
    sparkConf.set("spark.port.maxRetries","100")
    val sc = new SparkContext(sparkConf)

    val value: RDD[Int] = sc.makeRDD(List(4, 2, 3, 1),2)
    // 初始值,分区内规则,分区间规则
    val i: Int = value.aggregate(0)(_ + _, _ + _)
    println(i)


    // aggregateByKey zeroValue只会参与分区内计算
    // aggregate zeroValue 会参与分区内计算和分区间计算
    val i1: Int = value.aggregate(10)(_ + _, _ + _)
    println(i1) // 40  (1,2,10) (3,4,10) => 10,13,17 => 40

    sc.stop()

  }

}
